﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<JobDescOnline.Presentation.Models.JobDescriptionModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit Job Description - Review JobDesc!
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        function JobCombo(departmentID) {
            if (departmentID != "") {
                $.ajax({
                    url: "/JobTitle/Combo",
                    type: "POST",
                    data: { DepartmentID: departmentID, Name: "JobDescription.JobTitleID" },
                    success: function (msg) {
                        if (msg) {
                            $("#JobTitleBody").html(msg);
                        }
                    }
                });

                $.ajax({
                    url: "/JobTitle/Combo",
                    type: "POST",
                    data: { DepartmentID: departmentID, Name: "JobDescription.ReportToJobTitleID" },
                    success: function (msg) {
                        if (msg) {
                            $("#ReportToBody").html(msg);
                        }
                    }
                });
            } else {
                $("#JobTitleBody").html("");
                $("#ReportToBody").html("");
            }

            return false;
        }

        function JobTitleChange(ID) {
            $.ajax({
                url: "/JobTitle/RetrieveData/" + ID,
                type: "GET",
                success: function (json) {
                    $("#mineducation").html(json.MinEducation + " " + json.Major);
                    $("#workingexperience").html(json.WorkingExperience);
                    $("#functionalcompetency").html(json.FunctionalCompetency);
                    $("#challenge").html(json.Challenge);
                    $("#workingexperience").html(json.WorkingExperience);
                    $("#authority").html(json.Authority);
                }
            });
        }

        function InsertResponsibility() {
            $.ajax({
                url: "/JobDescResponsibility/Create",
                type: "POST",
                data: { JobDescriptionID: $("[name=ID]").val(), MainTask: $("[name=MainTask]").val(), Activities: $("[name=Activities]").val() },
                success: function (msg) {
                    if (msg) {
                        $("#ResponBody").html(msg);
                        $("[name=MainTask]").val("");
                        $("[name=Activities]").val("");
                    }
                }
            });

            return false;
        }

        function SaveResponsibility(id) {
            $.ajax({
                url: "/JobDescResponsibility/Edit/" + id,
                type: "POST",
                data: { JobDescriptionID: $("[name=ID]").val(), MainTask: $("[name=MainTask" + id + "]").val(), Activities: $("[name=Activities" + id + "]").val() },
                success: function (msg) {
                    if (msg) {
                        $("#ResponBody").html(msg);
                        $("[name=MainTask]").val("");
                        $("[name=Activities]").val("");
                    }
                }
            });

            return false;
        }

        function DeleteResponsibility(id) {
            $.ajax({
                url: "/JobDescResponsibility/Delete/" + id,
                success: function (msg) {
                    if (msg) {
                        $("#ResponBody").html(msg);
                        $("[name=MainTask]").val("");
                        $("[name=Activities]").val("");
                    }
                }
            });

            return false;
        }

        function InsertRelationship(type) {
            $.ajax({
                url: "/JobDescRelationShip/Create",
                type: "POST",
                data: { JobDescriptionID: $("[name=ID]").val(), Department: $("[name=Department" + type + "]").val(), Purpose: $("[name=Purpose" + type + "]").val(), TypeRelation: type },
                success: function (msg) {
                    if (msg) {
                        $("#RelationBody" + type).html(msg);
                        $("[name=Department]").val("");
                        $("[name=Purpose]").val("");
                    }
                }
            });

            return false;
        }

        function SaveRelationship(id, type) {
            $.ajax({
                url: "/JobDescRelationShip/Edit/" + id,
                type: "POST",
                data: { JobDescriptionID: $("[name=ID]").val(), Department: $("[name=Department" + id + "]").val(), Purpose: $("[name=Purpose" + id + "]").val(), TypeRelation: type },
                success: function (msg) {
                    if (msg) {
                        $("#RelationBody" + type).html(msg);
                        $("[name=Department]").val("");
                        $("[name=Purpose]").val("");
                    }
                }
            });

            return false;
        }

        function DeleteRelationship(id, type) {
            $.ajax({
                url: "/JobDescRelationShip/Delete/" + id,
                success: function (msg) {
                    if (msg) {
                        $("#RelationBody" + type).html(msg);
                        $("[name=Department]").val("");
                        $("[name=Purpose]").val("");
                    }
                }
            });

            return false;
        }

        function InsertPI(jobDescResponsibilityID) {
            $.ajax({
                url: "/PerformanceIndicator/Create",
                type: "POST",
                data: { JobDescResponsibilityID: jobDescResponsibilityID, PI: $("[name=PIS" + jobDescResponsibilityID + "]").val() },
                success: function (msg) {
                    if (msg) {
                        $("#PIBody" + jobDescResponsibilityID).html(msg);
                        $("[name=PI" + jobDescResponsibilityID + "]").val("");
                    }
                }
            });

            return false;
        }

        function SavePI(id, pid) {
            $.ajax({
                url: "/PerformanceIndicator/Edit/" + id,
                type: "POST",
                data: { PI: $("[name=PI" + id + "]").val() },
                success: function (msg) {
                    if (msg) {
                        $("#PIBody" + pid).html(msg);
                    }
                }
            });

            return false;
        }

        function DeletePI(id, pid) {
            $.ajax({
                url: "/PerformanceIndicator/Delete/" + id,
                type: "POST",
                success: function (msg) {
                    if (msg) {
                        $("#PIBody" + pid).html(msg);
                    }
                }
            });

            return false;
        }

        $(document).ready(function () {
            JobTitleChange($("[name=JobDescription.JobTitleID]").val());
        });
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Job Description - Ubah Data!</h2>

    <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm()) { %>
        <%: Html.ValidationSummary(true) %>

        <fieldset>
            <legend>1. Job Identification:</legend>
            <%: Html.Hidden("ID", ViewData["ID"])%>
            <table class="entry">
                <tr>
                    <td style="width: 230px;"><%: Html.LabelFor(model => model.JobDescription.DepartmentID)%></td>
                    <td>
                        <%: Html.DropDownList("JobDescription.DepartmentID", (IEnumerable<SelectListItem>)HttpContext.Current.Application["ComboDepartment"], "--Select One--", new { onChange = "JobCombo(this.value);" })%>
                        <%: Html.ValidationMessageFor(model => model.JobDescription.DepartmentID)%>
                    </td>
                </tr>
                <tr>
                    <td><%: Html.LabelFor(model => model.JobDescription.JobTitleID)%></td>
                    <td>
                        <div id="JobTitleBody">
                            <%: Html.DropDownList("JobDescription.JobTitleID", (IEnumerable<SelectListItem>)ViewData["ComboJobTitle"], "--Select One--", new { onChange = "JobTitleChange(this.value);" })%>
                        </div>
                        <%: Html.ValidationMessageFor(model => model.JobDescription.JobTitleID)%>
                    </td>
                </tr
                <tr>
                    <td><%: Html.LabelFor(model => model.JobDescription.ReportToJobTitleID)%></td>
                    <td>
                        <div id="ReportToBody">
                            <%: Html.DropDownList("JobDescription.ReportToJobTitleID", (IEnumerable<SelectListItem>)ViewData["ComboJobTitle"], "--Select One--")%>
                        </div>
                        <%: Html.ValidationMessageFor(model => model.JobDescription.ReportToJobTitleID)%>
                    </td>
                </tr>
                <tr>
                    <td><%: Html.LabelFor(model => model.JobDescription.Location)%></td>
                    <td>
                        <%: Html.DropDownList("JobDescription.Location", (IEnumerable<SelectListItem>)HttpContext.Current.Application["Location"], "--Select One--")%>
                        <%: Html.ValidationMessageFor(model => model.JobDescription.Location)%>
                    </td>
                </tr>
            </table>
        </fieldset>
        <fieldset>
            <legend>2. <%: Html.LabelFor(model => model.JobDescription.JobPurpose)%> (Tujuan Jabatan):</legend>
            <%: Html.TextAreaFor(model => model.JobDescription.JobPurpose, new { style = "width: 900px", rows = "5" })%>
            <%: Html.ValidationMessageFor(model => model.JobDescription.JobPurpose)%>
        </fieldset>

        <fieldset>
            <legend>3. Key Accountability Area (Tanggung Jawab Utama):</legend>
            <table class="withborder">
                <thead>
                    <tr>
                        <th style="width: 300px">Main Tasks</th>
                        <th>Activities</th>
                        <th style="width: 55px"></th>
                    </tr>
                </thead>
                <tbody id="ResponBody">
                <% foreach (var res in Model.JobDescResponsibilityModel) { %>
                    <tr valign="top">
                        <td>
                            <%= Html.Hidden("JobDescriptionID" + res.ID.ToString(), res.JobDescriptionID)%>
                            <%= Html.TextBox("MainTask" + res.ID.ToString(), res.MainTask)%>
                        </td>
                        <td>
                            <%= Html.TextArea("Activities" + res.ID.ToString(), res.Activities)%>
                        </td>
                        <td style="text-align: center">
                            <input type="button" onclick="return SaveResponsibility(<%= res.ID.ToString() %>);" value="Simpan" />
                            <input type="button" onclick="return DeleteResponsibility(<%= res.ID.ToString() %>);" value="Hapus" />
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            PI:<br />
                            <div id="PIBody<%= res.ID.ToString() %>">
                                <% foreach (var pi in res.PI) { %>
                                    &nbsp;&nbsp;&nbsp;<%= Html.TextBox("PI" + pi.ID.ToString(), pi.PI, new { @style = "width: 320px" })%>
                                    <input type="button" value="Simpan" onclick="return SavePI(<%= pi.ID.ToString() %>, <%= res.ID.ToString() %>);" />
                                    <input type="button" value="Hapus" onclick="return DeletePI(<%= pi.ID.ToString() %>, <%= res.ID.ToString() %>);" /><br /><br />
                                <% } %>
                            </div>
                            &nbsp;&nbsp;&nbsp;<%= Html.TextBox("PIS" + res.ID.ToString(), "", new { @style = "width: 400px" })%>
                            <input type="button" value="Tambah" onclick="return InsertPI(<%= res.ID.ToString() %>);" />
                        </td>
                        <td></td>
                    </tr>
                <% } %>
                </tbody>
                <tfoot>
                    <tr valign="top">
                        <td><%= Html.TextBox("MainTask", "")%></td>
                        <td><%= Html.TextArea("Activities", "")%></td>
                        <td><input type="button" value="Tambah" onclick="return InsertResponsibility();" /></td>
                    </tr>
                </tfoot>
            </table>
        </fieldset>

        <fieldset>
            <legend>4. Working RelationShip (Hubungan Kerja): </legend>
            <table class="withborder">
                <thead>
                    <tr>
                        <th>Hubungan Internal</th>
                        <th>Tujuan</th>
                        <th style="width: 55px"></th>
                    </tr>
                </thead>
                <tbody id="RelationBodyInternal">
                <% foreach (var res in Model.JobDescRelationShipInternal) { %>
                    <tr valign="top">
                        <td>
                            <%= Html.Hidden("JobDescriptionID" + res.ID.ToString(), res.JobDescriptionID)%>
                            <%= Html.TextBox("Department" + res.ID.ToString(), res.Department)%>
                        </td>
                        <td><%= Html.TextArea("Purpose" + res.ID.ToString(), res.Purpose)%></td>
                        <td style="text-align: center">
                            <input type="button" onclick="return SaveRelationship(<%= res.ID.ToString() %>, 'Internal');" value="Simpan" />
                            <input type="button" onclick="return DeleteRelationship(<%= res.ID.ToString() %>, 'Internal');" value="Hapus" />
                        </td>
                    </tr>
                <% } %>
                </tbody>
                <tfoot>
                    <tr valign="top">
                        <td><%= Html.TextBox("DepartmentInternal", "") %></td>
                        <td><%= Html.TextArea("PurposeInternal", "") %></td>
                        <td><input type="button" value="Tambah" onclick="return InsertRelationship('Internal');" /></td>
                    </tr>
                </tfoot>
            </table>
            <br />
            <table class="withborder">
                <thead>
                    <tr>
                        <th>Hubungan External</th>
                        <th>Tujuan</th>
                        <th style="width: 55px"></th>
                    </tr>
                </thead>
                <tbody id="RelationBodyExternal">
                <% foreach (var res in Model.JobDescRelationShipExternal) { %>
                    <tr valign="top">
                        <td>
                            <%= Html.Hidden("JobDescriptionID" + res.ID.ToString(), res.JobDescriptionID)%>
                            <%= Html.TextBox("Department" + res.ID.ToString(), res.Department)%>
                        </td>
                        <td><%= Html.TextArea("Purpose" + res.ID.ToString(), res.Purpose)%></td>
                        <td style="text-align: center">
                            <input type="button" onclick="return SaveRelationship(<%= res.ID.ToString() %>, 'External');" value="Simpan" />
                            <input type="button" onclick="return DeleteRelationship(<%= res.ID.ToString() %>, 'External');" value="Hapus" />
                        </td>
                    </tr>
                <% } %>
                </tbody>
                <tfoot>
                    <tr valign="top">
                        <td><%= Html.TextBox("DepartmentExternal", "") %></td>
                        <td><%= Html.TextArea("PurposeExternal", "") %></td>
                        <td><input type="button" value="Tambah" onclick="return InsertRelationship('External');" /></td>
                    </tr>
                </tfoot>
            </table>
        </fieldset>

        <fieldset>
            <legend>5. Knowledge, Experience And Competency</legend>
            <b>Minimum Formal Education Level:</b><br />
            <div id="mineducation"></div><br />

            <b>Working Experience</b><br />
            <div id="workingexperience"></div><br />

            <b>Functional Competencies</b><br />
            <div id="functionalcompetencies"></div>
        </fieldset>

        <fieldset>
            <legend>6. Challenge (Tantangan)</legend>
            <div id="challenge"></div>
        </fieldset>

        <fieldset>
            <legend>7. Dimension</legend>
            <table>
                <tr>
                    <td><%: Html.LabelFor(model => model.JobDescription.Capex)%></td>
                    <td><%: Html.TextBoxFor(model => model.JobDescription.Capex) %></td>
                </tr>
                <tr>
                    <td><%: Html.LabelFor(model => model.JobDescription.Opex)%></td>
                    <td><%: Html.TextBoxFor(model => model.JobDescription.Opex) %></td>
                </tr>
                <tr>
                    <td>Number of Subordinates</td>
                    <td>
                        <b>Langsung</b><br />
                        <%: Html.TextBoxFor(model => model.JobDescription.DirectSubordinates) %><br />

                        <b>Tidak Langsung</b><br />
                        <%: Html.TextBoxFor(model => model.JobDescription.IndirectSubordinates) %><br />
                    </td>
                </tr>
            </table>
        </fieldset>

        <fieldset>
            <legend>8. Freedom To Act(Kewenangan)</legend>
            <div id="authority"></div>
        </fieldset>

        <fieldset>
            <legend>9. Organization Structure</legend>
            <center>
                <img id="imageorganization" />
            </center>
        </fieldset>

        <input type="submit" value="Simpan" />
    <% } %>

    <div><%: Html.ActionLink("Kembali", "Index") %></div>
</asp:Content>